package com.xuelang.pipeline.artifact.client.resource.enums;

import lombok.Getter;

/**
 * 制品工具枚举类
 *
 * @author xiwen.zxg
 * @since 2024/6/27
 */
@Getter
public enum ArtifactToolEnum {

    ;
    /**
     * 仓库角色
     */
    public enum RoleEnum {
        /**
         * 管理员
         */
        MANAGER("MANAGER", "管理员"),
        /**
         * 开发人员
         */
        DEVELOPER("DEVELOPER", "开发人员"),
        /**
         * 普通用户
         */
        USER("USER", "普通用户");

        /**
         * key
         */
        private final String key;
        /**
         * 名称
         */
        private final String name;

        RoleEnum(String key, String name) {
            this.key = key;
            this.name = name;
        }

        public static boolean isValid(String roleName) {
            for (RoleEnum item : RoleEnum.values()) {
                if (item.key.equals(roleName)) {
                    return true;
                }
            }
            return false;
        }

        /**
         * 通过key获取枚举类
         *
         * @param key
         * @return
         */
        public static RoleEnum getByKey(String key) {
            for (RoleEnum item : RoleEnum.values()) {
                if (item.key.equals(key)) {
                    return item;
                }
            }
            throw new IllegalArgumentException("key:" + key);
        }
    }

    /**
     * 数据来源
     */
    public enum DataSourceEnum {
        /**
         * 制品工具
         */
        TOOL("TOOL", "制品工具"),
        /**
         * 制品仓库
         */
        ARTIFACT("ARTIFACT", "制品仓库");

        /**
         * key
         */
        private final String key;
        /**
         * 名称
         */
        private final String name;

        DataSourceEnum(String key, String name) {
            this.key = key;
            this.name = name;
        }

        public static boolean isValid(String dataSource) {
            for (DataSourceEnum item : DataSourceEnum.values()) {
                if (item.key.equals(dataSource)) {
                    return true;
                }
            }
            return false;
        }
    }

    /**
     * Maven仓库存储策略
     */
    public enum MavenStorageStrategyEnum {
        /**
         * 发布模式
         */
        RELEASE("RELEASE", "发布模式"),
        /**
         * 快照模式
         */
        SNAPSHOT("SNAPSHOT", "快照模式"),
        /**
         * 混合模式
         */
        MIXED("MIXED", "混合模式");
        /**
         * key
         */
        private final String key;
        /**
         * 名称
         */
        private final String name;

        MavenStorageStrategyEnum(String key, String name) {
            this.key = key;
            this.name = name;
        }

        public static boolean isValid(String mavenStorageStrategy) {
            for (MavenStorageStrategyEnum item : MavenStorageStrategyEnum.values()) {
                if (item.key.equals(mavenStorageStrategy)) {
                    return true;
                }
            }
            return false;
        }
    }

    /**
     * 制品仓库类型
     */
    public enum ArtifactTypeEnum {
        /**
         * 通用制品库
         */
        GENERIC("GENERIC", "通用制品库"),
        /**
         * 镜像仓库
         */
        DOCKER("DOCKER", "镜像仓库"),
        /**
         * Maven仓库
         */
        MAVEN("MAVEN", "Maven仓库"),
        /**
         * Npm仓库
         */
        NPM("NPM", "Npm仓库");

        /**
         * key
         */
        private final String key;
        /**
         * 名称
         */
        private final String name;

        ArtifactTypeEnum(String key, String name) {
            this.key = key;
            this.name = name;
        }

        public static boolean isValid(String artifactType) {
            for (ArtifactTypeEnum item : ArtifactTypeEnum.values()) {
                if (item.key.equals(artifactType)) {
                    return true;
                }
            }
            return false;
        }
        public static ArtifactTypeEnum getByKey(String key) {
            for (ArtifactTypeEnum item : ArtifactTypeEnum.values()) {
                if (item.key.equals(key)) {
                    return item;
                }
            }
            throw new IllegalArgumentException("key:" + key);
        }
    }

    /**
     * 开放范围
     */
    public enum OpenScopeEnum {
        /**
         * 项目级-私有
         */
        PROJECT("PROJECT", "项目级-私有"),
        /**
         * 团队级-公共
         */
        PUBLIC("PUBLIC", "团队级-公共");
        /**
         * key
         */
        private final String key;
        /**
         * 名称
         */
        private final String name;

        OpenScopeEnum(String key, String name) {
            this.key = key;
            this.name = name;
        }

        public static boolean isValid(String openScope) {
            for (OpenScopeEnum item : OpenScopeEnum.values()) {
                if (item.key.equals(openScope)) {
                    return true;
                }
            }
            return false;
        }
    }

    /**
     * 项目编码
     */
    public enum ProjectCodeEnum {
        /**
         * 默认公开仓库
         */
        INTERNAL_ARTIFACT("INTERNAL_ARTIFACT", "默认公开仓库"),
        /**
         * 持续部署工具
         */
        TOOL_ARTIFACT("TOOL_ARTIFACT", "制品工具其他仓库");

        /**
         * key
         */
        private final String key;
        /**
         * 名称
         */
        private final String name;

        ProjectCodeEnum(String key, String name) {
            this.key = key;
            this.name = name;
        }

        public static boolean isValid(String projectCode) {
            for (ProjectCodeEnum item : ProjectCodeEnum.values()) {
                if (item.key.equals(projectCode)) {
                    return true;
                }
            }
            return false;
        }

    }
}
